package com.huel.components;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.huel.bean.Btn;
import com.huel.bean.Goods;
import com.huel.bean.Item;
import com.huel.taobaostore.R;

import java.util.ArrayList;
import java.util.List;

public class ItemRecycleViewAdapter extends RecyclerView.Adapter<ItemRecycleViewAdapter.ViewHolder> {

    private List<Goods> mList ;

    static class ViewHolder extends RecyclerView.ViewHolder{
        View myView;
        ImageView imageView;
        TextView title,price,count;
        public ViewHolder(View itemView) {
            super(itemView);
            myView = itemView;
            imageView = (ImageView) itemView.findViewById(R.id.cart_pic);
            title = (TextView) itemView.findViewById(R.id.cart_title);
            price = (TextView) itemView.findViewById(R.id.cart_price);
            count = (TextView) itemView.findViewById(R.id.cart_cnt);
        }
    }
        //数据源
    public ItemRecycleViewAdapter(List<Goods> list){
        this.mList = list;
    }


    @NonNull
    @Override
    public ItemRecycleViewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout,null);
        final ItemRecycleViewAdapter.ViewHolder holder = new ItemRecycleViewAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ItemRecycleViewAdapter.ViewHolder holder, int position) {
        Goods item = mList.get(position);
//        请求网络图片
        Glide.with(holder.myView).load(item.getPic()).into(holder.imageView);
        holder.title.setText(item.getName());
        holder.price.setText("促销价："+item.getPrice());
        holder.count.setText("当前数量为:1 件");
    }
    @Override
    public int getItemCount() {
        return mList.size();
    }


}
